﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Procenge.PortalVendas.Models;

namespace Procenge.PortalVendas.Controllers
{
    public class CartaoController : Controller
    {
        //
        // GET: /Cartao/

        CartaoModels contexto = new CartaoModels();

        public ActionResult Index()
        {
            return View(contexto.ListarCartao());
        }

        //
        // GET: /Cartao/Details/5

        public ActionResult Details(int id)
        {
            return View(contexto.BuscarCartaoCodigo(id));
        }

        //
        // GET: /Cartao/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Cartao/Create

        [HttpPost]
        public ActionResult Create(Cartao cartao)
        {
            try
            {
                // TODO: Add insert logic here
                contexto.CriarCartao(cartao);
                    

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Cartao/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View(contexto.BuscarCartaoCodigo(id));
        }

        //
        // POST: /Cartao/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                Cartao cartao = contexto.BuscarCartaoCodigo(id);
                UpdateModel(cartao);
                contexto.Salvar();
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Cartao/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(contexto.BuscarCartaoCodigo(id));
        }

        //
        // POST: /Cartao/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                contexto.RemoverCartao(id);
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
